package com.lt.service.impl;

import com.lt.entity.Login;
import com.lt.mapper.LoginMapper;
import com.lt.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author :liteng
 * @Time : 2023-10-21 23:09
 */

@Service
@Slf4j
public class LoginServiceImpl implements LoginService {

    private final LoginMapper loginMapper;

    public LoginServiceImpl(LoginMapper loginMapper) {
        this.loginMapper = loginMapper;
    }


    @Override
    public int loginAuth(Long num, String passwd, int identity) {

        Boolean i = loginMapper.queryUser(num, identity);
        if (!i) {
            log.info("用户不存在");
            return -1;
        }
        Login item = loginMapper.queryItem(num);
        if (!passwd.equals(item.getPassword())) {
            log.info("密码错误");
            return 0;
        }
        return 1;

    }

    @Override
    public Boolean loginAuth(Long num, String passwd) {
        Login item = loginMapper.queryItem(num);
        if (!passwd.equals(item.getPassword())) {
            log.info("密码错误");
            return false;
        }
        return true;
    }

    @Override
    public String getUserName(Long num, int identity) {
        String name = loginMapper.selectName(num, identity);
        return name;
    }

    @Override
    public void changePassword(Long num, String passwd) {
        loginMapper.updatePassword(new Login(null, num, passwd, null));
    }
}

